package animix.blue.server.user.mapper;


import animix.blue.server.common.bean.model.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface RoleMapper {

    @Select({
            "<script>",
            "select * from tb_role where id in",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    public List<Role> listByIds(@Param("ids") Integer[] ids);

    @SelectProvider(type = RoleProvider.class, method = "list")
    public List<Role> list(Map<String, Object> para);

    @Select("select * from tb_role where id = #{id}")
    public Role getById(Integer id);

    @Select("select * from tb_role where name = #{name}")
    public Role getByName(String name);

    @Insert("insert into tb_role (name, role_desc, created, updated) values" +
            "(#{name}, #{roleDesc}, #{created}, #{updated})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", before = false, resultType = int.class)
    public void add(Role role);

    @UpdateProvider(type = RoleProvider.class, method = "updateByIdSelective")
    public void updateByIdSelective(Role role);
}
